﻿using DevExpress.ExpressApp.DC;

namespace EasyXaf.EntityDesigner.ModelBuilders;

public class EntityPropertyBuilder<TProperty> : IEntityPropertyBuilder
{
    private readonly IMemberInfo _memberInfo;

    public EntityPropertyBuilder(IMemberInfo memberInfo)
    {
        _memberInfo = memberInfo;
    }

    public EntityPropertyBuilder<TProperty> AddAttribute(Func<IMemberInfo, Attribute> action)
    {
        var attribute = action(_memberInfo);
        if (attribute != null)
        {
            _memberInfo.AddAttribute(attribute, false);
        }
        return this;
    }

    public EntityPropertyBuilder<TProperty> RemoveAttribute(Func<IMemberInfo, Attribute> action)
    {
        var attribute = action(_memberInfo);
        if (attribute != null)
        {
            ((BaseInfo)_memberInfo).RemoveAttribute(attribute);
        }
        return this;
    }
}
